<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数据管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/style/admin.css" media="all">
		 
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						
						<!--查询条件start-->
						 <div class="layui-form layui-card-header layuiadmin-card-header-auto">
					        <div class="layui-form-item">
					        		
					           <?php foreach ($filedSearchList as $v){  ?>
					           	    <?php echo $component->serchKj($v['u7'],$v['u2'],$v['u1'] ,"",$v['u3'] ,$v['id']) ?>
							   <?php } ?>
					          
					          <div class="layui-inline">
					           <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
					              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					           </button>
					          </div>
					          
					        </div>
					      </div>
						<!--查询条件end-->
						
						<!--<div class="layui-card-header">内容管理</div>-->
						<div class="layui-card-body">
							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a onclick="layOpen('添加内容', '/<?= ADMIN_NAME ?>/zhengcedongtai/add?table_id=<?=$table_id?>','100%','100%')" href="javascript:;" class="layui-btn"><i class="layui-icon"></i>添加数据</a>
							</div>
							
							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a href="/<?= ADMIN_NAME ?>/inc/exportexcelbytableid?table_id=<?=$table_id?>" target="_blank" class="layui-btn layui-btn-warm"><i class="layui-icon layui-icon-download-circle"></i>导出数据</a>
							</div>
							
							
							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a href="/<?= ADMIN_NAME ?>/inc/exportexcelbytableid?table_id=<?=$table_id?>&type=muban" target="_blank" class="layui-btn layui-btn-primary"><i class="layui-icon layui-icon-download-circle"></i>下载导入模版</a>
							</div>
							
							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a onclick="layOpen('导入用户', '/<?= ADMIN_NAME ?>/zhengcedongtai/daoru?table_id=<?=$table_id?>','100%','100%')" href="javascript:;"  class="layui-btn layui-btn-normal"><i class="layui-icon layui-icon-upload"></i>导入数据</a>
							</div>

							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a onclick="onClickDeleteBtn('all','删除选中项')" href="javascript:;"    class="layui-btn layui-btn-danger"><i class="layui-icon layui-icon-delete"></i>批量删除</a>
							</div>
							
<!--							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">-->
<!--								<a onclick="onClickTongbuBtn('all','同步选中项')" href="javascript:;"    class="layui-btn layui-bg-gray"><i class="layui-icon layui-icon-release"></i>同步到四方平台</a>-->
<!--							</div>-->

							<div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
								<a onclick="onClickTongbuBtn2()" href="javascript:;"    class="layui-btn layui-bg-gray"><i class="layui-icon layui-icon-release"></i>同步到四方平台</a>
							</div>


							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>

							<script type="text/html" id="test-table-operate-barDemo" >
								<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
 							</script>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/layui.js"></script>
		<script>
			layui.config({
				base: '<?= RESOURCES ?>/layuiadmin/layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laydate', 'contlist'], function() {
				var $ = layui.$,
				    table = layui.table,
					admin = layui.admin,
					laydate = layui.laydate,
					form = layui.form;

				table.render({
					elem: '#test-table-operate',
					url: '/<?= ADMIN_NAME ?>/zhengcedongtai/gettablelistbytableid?table_id=<?=$table_id?>',
					height: 'full-100',
				    cellMinWidth: 80,
				    page: true,
				    limit: 20,
					cols: [
						<?=$filedlistJson?>
					],
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});
				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'get_table_list') {
						var id = data.id;
						//layOpen("修改管理员","<?= ADMIN_NAME ?>/table/editpassword?id="+id);
						newTab(data.u2+'内容管理', '/<?= ADMIN_NAME ?>/'+data.u8+'/index?table_id='+data.id);
						
						
					} else if(obj.event === 'del') {
						layer.confirm('确认放入回收站？', function(index) {
							layer.close(index);
							var id = data.id;
							var table_id ="<?=$table_id?>";
							//myAjax("/<?= ADMIN_NAME ?>/zhengcedongtai/delete?"+"id="+id+"&table_id="+table_id,"get","");
							$.ajax({          
								  url: "/<?= ADMIN_NAME ?>/zhengcedongtai/delete?"+"id="+id+"&table_id="+table_id,
						          type: "get",
						          data: "",
						          dataType: 'JSON',
						          success: function(data) {            
										if(data.status) {              
											var index = parent.layer.getFrameIndex(window.name);              
											parent.layer.msg(data.msg, {
												icon: 6
											}); //添加成功后提示
										} else {              
											parent.layer.msg(data.msg, {
												icon: 5,
												time: 1000
											});            
										}  
										//更新行数据
										obj.del(); //删除对应行（tr）的DOM结构，并更新缓存        
									}
								})
							//window.location.href="/<?= ADMIN_NAME ?>/zhengcedongtai/delete?id="+id;
						});
					} else if(obj.event === 'edit') {
						var id = data.id;
						layOpen("修改内容","/<?= ADMIN_NAME ?>/zhengcedongtai/edit?table_id=<?=$table_id?>&id="+id,"100%","100%");
						
					}else if(obj.event === 'setfield'){
			        		newTab(data.u2+'字段管理', '/<?= ADMIN_NAME ?>/filed/index?table_id='+data.id);
			       	}
					
					
				});
				
				laydate.render({
					elem:'.ghy-date',//制定元素
					    type:'datetime',
					    range:true,//开启左右面板
					    //min:'2017-09-1',//
					    //max:'2017-10-1',//规定时间期限
					    trigger:'mouseover',//定义鼠标悬停时弹出控件
					    show:false,//默认显示
					    //position:'absolute',
					    //btns:['clear','now'],//工具按钮 默认值['clear', 'now', 'confirm']
					    //theme:'#393D49',//主题颜色
					    calendar:true,//是否显示公历节日
//					    mark:{
//					        '2017-9-21': '发布'//自定义标注重要日子
//					    },
					     
				}); 
				
			//监听搜索
		    form.on('submit(LAY-app-contlist-search)', function(data){
		      var field = data.field;
		      //alert(field);
		      //执行重载
		      table.reload('test-table-operate', {
		        where: field
		      });
		    });
		    
		     
			
			//	批量删除
		    window.onClickDeleteBtn = function(type,name){
		    	  layer.confirm('确认要'+name+'吗？', {
		    		icon: 3, title:'确认批量操作',
		              btn: ['确认', '取消']
		          }, function (index, layero) {
		        	  layer.closeAll('dialog'); 
		        	   //获取checkbox的值
	       	            var checkStatus = table.checkStatus('test-table-operate');
		        	    var ids = [];
		        	    $(checkStatus.data).each(function (i, o) {//o即为表格中一行的数据
		        	        ids.push(o.id);
		        	    });
		        	    if (ids.length < 1) {
		        	        layer.msg('无选中项');
		        	        return false;
		        	    }
		        	    if(ids.length >= 100 ){
		        	    	layer.msg("选择不能超过100项");
		        	    	return false;
		        	    }
		        	    
		        	    ids = ids.join(",");
	       	  
		        	    
		        	    
		        	    //	分别请求不同的数据接口
		        	    if(type=="all"){
		        	    	//处理全部类型的数据
		        	    	$.ajax({          
								  url: "/<?= ADMIN_NAME ?>/zhengcedongtai/delete?"+"id="+ids+"&table_id=<?=$table_id?>",
						          type: "get",
						          data: "",
						          dataType: 'JSON',
						          success: function(data) {            
										if(data.status) {              
											var index = parent.layer.getFrameIndex(window.name);              
											parent.layer.msg(data.msg, {
												icon: 6
											}); //添加成功后提示
										} else {              
											parent.layer.msg(data.msg, {
												icon: 5,
												time: 1000
											});            
										}  
										//更新行数据
										location.reload();    
									}
								})
		        	    }else if(type="pretreatmentguanjianci"){
		        	    	layer.msg("暂无操作类型"); //添加成功后提示
		        	    	
		        	    }
		        	    
		              }
		           );
		    	  };
		    	  
		    	  //onClickTongbuBtn 同步到四方平台
		    	  window.onClickTongbuBtn = function(type,name){
			    	  layer.confirm('确认要'+name+'吗？', {
			    		icon: 3, title:'确认批量操作',
			              btn: ['确认', '取消']
			          }, function (index, layero) {
			        	  layer.closeAll('dialog'); 
			        	   //获取checkbox的值
		       	            var checkStatus = table.checkStatus('test-table-operate');
			        	    var ids = [];
			        	    $(checkStatus.data).each(function (i, o) {//o即为表格中一行的数据
			        	        ids.push(o.id);
			        	    });
			        	    if (ids.length < 1) {
			        	        layer.msg('无选中项');
			        	        return false;
			        	    }
			        	    if(ids.length >= 100 ){
			        	    	layer.msg("选择不能超过100项");
			        	    	return false;
			        	    }
			        	    
			        	    ids = ids.join(",");
		       	  
			        	    
			        	    
			        	    //	分别请求不同的数据接口
			        	    if(type=="all"){
			        	    	//处理全部类型的数据
			        	    	$.ajax({          
									  url: "/api/indexdiy/inserttosifang?"+"ids="+ids+"&t=zhengcedongtai",
							          type: "get",
							          data: "",
							          dataType: 'JSON',
							          success: function(data) {            
											if(data.status) {              
												var index = parent.layer.getFrameIndex(window.name);              
												parent.layer.msg(data.msg, {
													icon: 6
												}); //添加成功后提示
											} else {              
												parent.layer.msg(data.msg, {
													icon: 5,
													time: 1000
												});            
											}  
											//更新行数据
											//location.reload();    
										}
									})
			        	    }else if(type="pretreatmentguanjianci"){
			        	    	layer.msg("暂无操作类型"); //添加成功后提示
			        	    	
			        	    }
			        	    
			              }
			           );
			    	  };

				window.onClickTongbuBtn2 = function (){
					$.ajax({
						url: "/manage/zhengceku/tongbuData",
						type: "post",
						data: "",
						dataType: 'JSON',
						success: function(data) {
							layer.msg(data.msg);
						}
					})
				}
			    	  

			});
		</script>

	</body>
 
</html>

 <?php foreach ($filedShowList as $v){  ?>
 
	<?php if($v['u7']=='图片' ) { ?>
		    <script type="text/html" id="tp_<?=$v['u1']?>">
				<a href="javascript:;"  >
					<img   layer-src="{{d.<?=$v['u1']?>}}" src="{{d.<?=$v['u1']?>}}" width="100%" height="100%">
				</a>
    		</script>
	<?php } ?>
 	

 <?php } ?>

